import "reflect-metadata";
import { Container, Inject, Service } from "typedi";

interface Factory {
  create(): void;
}

@Service("bean.factory")
class BeanFactory implements Factory {
  create() {
    console.log("beanFactory");
  }
}

@Service("sugar.factory")
class SugarFactory implements Factory {
  create() {
    console.log("sugarFactory");
  }
}

@Service("water.factory")
class WaterFactory implements Factory {
  create() {
    console.log("waterFactory");
  }
}

@Service("coffee.maker")
class CoffeeMaker {
  beanFactory: BeanFactory;

  sugarFactory: SugarFactory;

  @Inject("water.factory")
  waterFactory!: WaterFactory;

  constructor(
    @Inject("bean.factory") beanFactory: BeanFactory,
    @Inject("sugar.factory") sugarFactory: SugarFactory,
  ) {
    this.beanFactory = beanFactory;
    this.sugarFactory = sugarFactory;
  }

  make() {
    this.beanFactory.create();
    this.sugarFactory.create();
    this.waterFactory.create();
  }
}

const coffeeMaker = Container.get<CoffeeMaker>("coffee.maker");
coffeeMaker.make();
